package com.tengju.data.infrastructure.repository.clickhouse.ods;

import com.tengju.data.domain.model.clickhouse.OdsMarketIndex;
import com.tengju.data.domain.model.clickhouse.OdsTengjuDataAchievementBounsLogRepository;
import com.tengju.data.domain.model.user.UserIdCode;
import com.tengju.data.infrastructure.persistence.mybatis.dataobject.OdsMarketIndexDO;
import com.tengju.data.infrastructure.persistence.mybatis.mapper.clickhouse.ods.OdsTengjuDataAchievementBounsLogDOMapper;
import com.tengju.data.infrastructure.repository.clickhouse.convert.OdsMarketIndexConvert;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

@Repository
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class OdsTengjuDataAchievementBounsLogRepositoryImpl implements
        OdsTengjuDataAchievementBounsLogRepository {

    private final OdsTengjuDataAchievementBounsLogDOMapper odsTengjuDataAchievementBounsLogDOMapper;

    @Override
    public int selectMarketIndexCount(UserIdCode idCode, Integer month) {
        return odsTengjuDataAchievementBounsLogDOMapper.selectMarketIndexCount(idCode.getValue(), month);
    }

    @Override
    public List<OdsMarketIndex> selectMarketIndexPage(UserIdCode idCode, Integer month, Integer offset, Integer pageSize) {
        List<OdsMarketIndexDO> odsMarketIndexDOList = odsTengjuDataAchievementBounsLogDOMapper.selectMarketIndexPage(idCode.getValue(), month, offset, pageSize);
        return odsMarketIndexDOList.stream()
                .map(OdsMarketIndexConvert::convert)
                .collect(Collectors.toList());
    }

    @Override
    public BigDecimal getMarketIndexAchievementTotal(UserIdCode idCode, Integer month) {
        return odsTengjuDataAchievementBounsLogDOMapper.getMarketIndexAchievementTotal(idCode.getValue(), month);
    }
}
